#ifndef SEQIOT_MQTT_H
#define SEQIOT_MQTT_H

#include "model.h"
#include "value.h"

//数据发送计划
typedef struct _pub_handler_t {
    void *handle;
    void *args;

    //哪些测点需要检查
    _Bool (*on_filter)(thing_model_t *, void *);

    //比较值是否发生变化
    _Bool (*on_compare)(value_t *local, value_t *remote, double max, double min);

    int (*on_write)(struct _pub_handler_t *, device_t *, segment_e);

    int (*on_flush)(struct _pub_handler_t *);
} pub_handler_t;

_Bool digital_filter(thing_model_t *model, void *args);

_Bool analog_filter(thing_model_t *model, void *args);

_Bool all_call_filter(thing_model_t *model, void *parameter);

_Bool totals_filter(thing_model_t *model, void *args);

_Bool catalog_filter(thing_model_t *model, void *args);

_Bool true_compare(value_t *local, value_t *remote);

_Bool value_changed_compare(value_t *local, value_t *remote, double max, double min);

//按segment检查
void check_segment(pub_handler_t *handler, void *parameter, device_t *device, segment_e segment);

//按设备检查
void check_device(pub_handler_t *handler, void *parameter, device_t *device);

//按通道检查
void check_channel(pub_handler_t *handler, void *parameter, channel_t *channel);

//变化数据检查
void check_next_sched(pub_handler_t *handler, seqiot_t *seqiot, time_t timestamp);

//全量数据变化检查
void check_whole(pub_handler_t *handler, seqiot_t *seqiot);

//变化数据发送
void publish_changed(pub_handler_t *handler, seqiot_t *seqiot);

#endif //SEQIOT_MQTT_H
